﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Gman.Entity.Entities;
using System.Collections.Generic;
using System.Web.Mvc;
using Gman.WebApp.ServiceControllers;
using System.Text;

namespace Gman.WebApp.Models
{
    public class PersonalModelValidator : ValidationBase
    {
        public List<KeyValuePair<string, string>> Validate(PersonalModel model)
        {
            PersonalModelValidator validator = new PersonalModelValidator();

            validator.RequiredFieldValidation("Personal.NomsPers", model.Personal.NomsPers, "Nombres");
            validator.RequiredFieldValidation("Personal.ApePers", model.Personal.ApePers, "Apellidos");
            validator.RequiredFieldValidation("Personal.NroDocuPers", model.Personal.NroDocuPers, "Nro Documento");
            validator.RequiredFieldValidation("Personal.CargoPers", model.Personal.CargoPers, "Cargo");
            validator.RequiredFieldValidation("Personal.AreaPers", model.Personal.AreaPers, "Área");

            return validator.ValidationList;
        }

        public static string BuildErrorMessage(List<KeyValuePair<string, string>> validationList)
        {
            StringBuilder sb = new StringBuilder(string.Empty);
            if (validationList.Count > 0)
                sb = new StringBuilder("Please fix the following error(s):");
            foreach (var validationError in validationList)
            {
                sb.Append("\n - ").Append(validationError.Value);
            }
            return sb.ToString();
        }
    }
}

